package com.example.f8399.testdemo.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;

import com.blankj.utilcode.util.ToastUtils;
import com.example.f8399.testdemo.BaseActivity;
import com.example.f8399.testdemo.R;
import com.example.f8399.testdemo.adapter.RcPageAdaper;
import com.example.f8399.testdemo.databinding.ActivityPagerLayoutManagerBinding;
import com.gcssloop.widget.PagerGridLayoutManager;
import com.gcssloop.widget.PagerGridSnapHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * @description 横向展示网格展示列表.
 *
 * http://www.gcssloop.com/tools/pager-grid-layoutmanager
 * @author lcfeng
 * @date   2018/8/24 17:19.
**/
public class PagerLayoutManagerActivity extends BaseActivity {

    ActivityPagerLayoutManagerBinding mBinding;
    private RcPageAdaper mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       mBinding = DataBindingUtil. setContentView(this,R.layout.activity_pager_layout_manager);
       mBinding.setAc(this);

       initView();
    }

    private void initView() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add("hi_" + i);

        }
        //横向发展
        mBinding.recyclerView.setLayoutManager(new PagerGridLayoutManager(2,4,PagerGridLayoutManager.HORIZONTAL));
        mAdapter = new RcPageAdaper(this, list);
        mBinding.recyclerView.setAdapter(mAdapter);

        PagerGridSnapHelper pagerGridSnapHelper = new PagerGridSnapHelper();
        pagerGridSnapHelper.attachToRecyclerView(mBinding.recyclerView);

        mAdapter.setOnItemClickListener(new RcPageAdaper.OnItemClickListener() {
            @Override
            public void onItemClick(String bean) {
                ToastUtils.showShort(bean);
            }
        });
    }
}
